#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

int numberOfH = 0;
int numberOfO = 0;
/* int* p_numberOfH = &numberOfH;
int* p_numberOfO = &numberOfO; */

void* collectH(void* pointH)
{
    while (*(char*)pointH != '\0')
    {
        /* code */
        if (*(char*)pointH == 'H')
        {
            numberOfH++;
            if ((numberOfH >= 2) && (numberOfO >= 1))
            {
                /* code */
                printf(" H2O ");
                numberOfH -= 2;
                numberOfO--;
            }
            
        }
        else if(*(char*)pointH == 'O')
        {
            numberOfO++;
        }
        else
        {
            printf("Not part of warter.\n");
        }
        (char*)pointH++;
    }
    
    return NULL;
}

void* collectO(void* pointO)
{
    
}

int main()
{
    char* inputString = "HHHOOHOHHOHHHHHOOOOOOOOHHHHHHHH";

    pthread_t tH;
    pthread_t tO;
    
    pthread_create(&tH, NULL, collectH, (void*)inputString);
    sleep(5);
    pthread_create(&tO, NULL, collectO, (void*)inputString);

    return 0;
}